﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.Model;
using Honestysoft.Baseframework.WebUI;

namespace Honestysoft.Financing.WebUI.Apply
{
    public partial class UcCompanyTextbox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.ClientScript.IsClientScriptIncludeRegistered("OuSelectScript"))
            {
                Page.ClientScript.RegisterClientScriptInclude("OuSelectScript", Globals.Home + "Apply/SelectOu.js");
            }
            if (!IsPostBack)
            {
                btnSelect.Text = ButtonText;
                btnSelect.CssClass = ButtonCssClass;
                btnSelect.Attributes.Add("onmouseover", "this.className='" + ButtonMouseOverClass + "'");
                btnSelect.Attributes.Add("onmouseout", "this.className='" + ButtonMouseOutClass + "'");
                btnSelect.OnClientClick = "return Select" + this.UniqueID + "();";
                if (!string.IsNullOrEmpty(Value))
                {
                    txtName.Text = Text;
                }
            }
        }
        /// <summary>
        /// 是否有效
        /// </summary>
        public bool Enabled
        {
            get
            {
                return btnSelect.Enabled;
            }
            set
            {
                btnSelect.Enabled = value;
            }
        }
        /// <summary>
        /// 控件宽度
        /// </summary>
        public Unit Width
        {
            get
            {
                return new Unit(txtName.Width.Value + btnSelect.Width.Value);
            }
            set
            {
                txtName.Width = new Unit(value.Value - btnSelect.Width.Value);
            }
        }
        /// <summary>
        /// 获取或设置已选择人员ID，以逗号隔开
        /// </summary>
        public string Value
        {
            get
            {
                return hidValue.Value;
            }
            set
            {
                hidValue.Value = value;
            }
        }
        /// <summary>
        /// 获取已选择名称，以逗号隔开
        /// </summary>
        public string Text
        {
            get
            {
                string text = txtName.Text;
                if (text == "")
                {
                    if (hidValue.Value != "")
                    {
                        Org_Company comp = new Honestysoft.BaseObject.BaseBusinessLogic<Org_Company>().GetEntity(hidValue.Value);
                        if (comp != null)
                        {
                            text = comp.CompName;
                            txtName.Text = text;
                        }
                    }
                }
                return text;
            }
        }
        /// <summary>
        /// 按钮显示文本（默认为“选择”）
        /// </summary>
        public string ButtonText
        {
            get
            {
                object obj = ViewState["ButtonText"];
                return obj == null ? "选择" : obj.ToString();
            }
            set
            {
                ViewState["ButtonText"] = value;
            }
        }
        /// <summary>
        /// 按钮样式
        /// </summary>
        public string ButtonCssClass
        {
            get
            {
                object obj = ViewState["ButtonCssClass"];
                return obj == null ? "btn_normal" : obj.ToString();
            }
            set
            {
                ViewState["ButtonCssClass"] = value;
            }
        }
        /// <summary>
        /// 按钮onmouseover样式
        /// </summary>
        public string ButtonMouseOverClass
        {
            get
            {
                object obj = ViewState["ButtonMouseOverClass"];
                return obj == null ? "btn_active" : obj.ToString();
            }
            set
            {
                ViewState["ButtonMouseOverClass"] = value;
            }
        }
        /// <summary>
        /// 按钮onmouseout样式
        /// </summary>
        public string ButtonMouseOutClass
        {
            get
            {
                object obj = ViewState["ButtonMouseOutClass"];
                return obj == null ? "btn_normal" : obj.ToString();
            }
            set
            {
                ViewState["ButtonMouseOutClass"] = value;
            }
        }
        /// <summary>
        /// 按钮客户端ID
        /// </summary>
        public string ButtonClientID
        {
            get
            {
                return btnSelect.ClientID;
            }
        }

        /// <summary>
        /// 用来显示文本的文本框ID
        /// </summary>
        public string DisplayTextBoxClientID
        {
            get
            {
                object obj = ViewState["DisplayTextBoxClientID"];
                return obj == null ? txtName.ClientID : obj.ToString();
            }
            set
            {
                ViewState["DisplayTextBoxClientID"] = value;
            }
        }

        /// <summary>
        /// 文本框可见性
        /// </summary>
        public bool TextBoxVisible
        {
            get
            {
                object obj = ViewState["TextBoxVisible"];
                return obj == null ? true : Convert.ToBoolean(obj);
            }
            set
            {
                ViewState["TextBoxVisible"] = value;
            }
        }

        /// <summary>
        /// 文本框的客户端ID
        /// </summary>
        public string TextBoxClientID
        {
            get
            {
                return txtName.ClientID;
            }
        }
    }
}